﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using WebNext.Domain.Entities;

namespace WebNext.DataAccess.Mappings
{
	public class EntryMap : EntityMap<Entry>
	{
		public EntryMap()
		{
			this.Table("Entries");
			this.Map(e => e.Title);
			this.Map(e => e.Content).CustomType<EntryContentJsonSerializer>();
			this.Map(e => e.Rank);
			this.Map(e => e.IsPublished);
			this.Map(e => e.CommentsEnabled);
			this.Map(e => e.Type).CustomType<EntryType>();
			this.Map(e => e.CultureId).CustomType<CultureId>();
			this.HasManyToMany<Tag>(e => e.Tags).Table("EntriesTags").ParentKeyColumn("EntryId").ChildKeyColumn("TagId").Cascade.None();
			this.HasMany<Comment>(e => e.Comments).KeyColumn("EntryId").Inverse().Cascade.AllDeleteOrphan();
		}
	}
}
